//
//  ProductsAndServicesViewController.m
//  Jingjing
//
//  Created by user on 15/11/11.
//  Copyright © 2015年 Mikeshihua. All rights reserved.
//

#import "ProductsAndServicesViewController.h"
#import "ProductsDetailViewController.h"
#import "ProductView.h"
#import "ServiceView.h"
#import "ServiewDeatilViewController.h"
#import "LoginViewController.h"
@interface ProductsAndServicesViewController ()
{
    ProductView *_productView;
    ServiceView *_serviceView;
    UIView *_segmentSelectView;
    UIView *_unSegmentSelectView;
}

@end

@implementation ProductsAndServicesViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    TopView *topView = [[TopView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, SCREEN_WIDTH, 64.0f)];
    [topView setTitile:@"活动&服务"];
    [self.view addSubview:topView];
    self.view.backgroundColor = [UIColor hexStringToColor:@"#f3f3f3"];

    
    UIView * segmentBackView = [[UIView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 46)];
    segmentBackView.backgroundColor = [UIColor hexStringToColor:@"#f3f3f3"];

    [self.view addSubview:segmentBackView];
    
    UISegmentedControl * segment = [[UISegmentedControl alloc]initWithItems:@[@"活动",@"服务"]];
    segment.frame = CGRectMake(-10, 0, SCREEN_WIDTH+20, 46.0f);
    segment.backgroundColor = [UIColor redColor];
    [segment addTarget:self action:@selector(changeTheBackgroundView:) forControlEvents:UIControlEventValueChanged];
    segment.selectedSegmentIndex = 0;
    NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:14],
                                             NSForegroundColorAttributeName: [UIColor hexStringToColor:COLOR_VALUE]};
    [segment setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];//设置文字属性
    NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:14],
                                               NSForegroundColorAttributeName: [UIColor hexStringToColor:COLOR_VALUE]};
    [segment setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];
    segment.backgroundColor = [UIColor clearColor];
    segment.tintColor = [UIColor clearColor];
    [self changeTheBackgroundView:segment];
    [segmentBackView addSubview:segment];

    _segmentSelectView = [[UIView alloc]initWithFrame:CGRectMake(0, 45.0f, SCREEN_WIDTH/2, 1.0f)];
    _segmentSelectView.backgroundColor = [UIColor blackColor];
    [segmentBackView addSubview:_segmentSelectView];
    
    _unSegmentSelectView = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2, 45.0f, SCREEN_WIDTH/2, 1.0f)];
    _unSegmentSelectView.backgroundColor = [UIColor lightGrayColor];
    [segmentBackView addSubview:_unSegmentSelectView];
}

//选项卡改变后，切换图
-(void)changeTheBackgroundView:(id)sender
{
    UISegmentedControl * segment = (UISegmentedControl *)sender;
    if (segment.selectedSegmentIndex == 0)
    {
        _segmentSelectView.backgroundColor = [UIColor blackColor];
        _unSegmentSelectView.backgroundColor = [UIColor lightGrayColor];
        //创建产品
       
        if (!_productView)
        {
            _productView = [[ProductView alloc]initWithFrame:CGRectMake(0, 46.0f+64.0f, SCREEN_WIDTH, SCREEN_HEIGHT-46.0f-64.0f-49.0f-16.0f) andTheDataUrl:nil];
            _productView.productDelegate = self;
            [self.view addSubview:_productView];
        }
        [self.view bringSubviewToFront:_productView];

        }else
    {
        _segmentSelectView.backgroundColor = [UIColor lightGrayColor];
        _unSegmentSelectView.backgroundColor = [UIColor blackColor];
        //创建服务
        if (!_serviceView)
        {
            _serviceView = [[ServiceView alloc]initWithFrame:CGRectMake(0, 46.0f+64.0f, SCREEN_WIDTH, SCREEN_HEIGHT-46.0f-64.0f-49.0f-16.0f) andTheDataUrl:nil];
            _serviceView.serviceDelegate = self;
            [self.view addSubview:_serviceView];
        }
        [self.view bringSubviewToFront:_serviceView];
        

    }
    
}

#pragma mark - ---------applyExamDelegate
-(void)goToTheProductDetailViewControllerWith:(Activity *)activity;
{
    
   
        ProductsDetailViewController *productDetailVC = [[ProductsDetailViewController alloc]init];
        productDetailVC.activitesTypeId = activity.activitesTypeId;
        productDetailVC.navTitle = activity.title;
        [self.navigationController pushViewController:productDetailVC animated:YES];
 
   
    
}

-(void)goToTheServiceDetailViewControllerWith:(NSString *)titleName withID:(NSString*)nameID{
    
    ServiewDeatilViewController* serview = [[ServiewDeatilViewController alloc]init];
    serview.titleName = titleName;
    serview.nameId = nameID;
    [self.navigationController pushViewController:serview animated:YES];
    
   
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
